# coding: utf-8

import os
import psutil
import signal


def kill(process_name):
    pid_dict = {}  # 保存键值对 pid:进程名
    pids = psutil.pids()  # 获取所有进程pid
    for pid in pids:
        process = psutil.Process(pid)
        pid_dict[pid] = process.name()

    for pid in pid_dict.keys():
        if pid_dict[pid] == process_name:
            try:
                os.kill(pid, signal.SIGABRT)
                print(f'已结束{process_name}:pid={pid}')
            except Exception:
                print(f'pid={pid}的{process_name}进程已不存在')
